<template>
  <div id="LeftRig">
    <ul>
      <li v-for="item in leftRig" :key="item.id">
        <span class="da" @click="Name(item.id)">{{ item.name }}</span>
        <span v-for="parent in item.children.slice(0, 2)" :key="parent.id" class="da2" @click="Desc(parent.id)">{{parent.name}}</span>
        <div class="right">
          <h4>分类推荐 
            <small>根据您的购买或浏览记录推荐</small>
          </h4>
          <ul>
            <li v-for="right in item.goods" :key="right.id" @click="rights(right.id)">
              <div class="lazy">
                <img :src="right.picture" alt="">
                <div>
                  <p>{{right.name}}</p>
                  <p>{{right.desc}}</p>
                  <p>{{right.price}}</p>
                </div>
              </div>
            </li>
          </ul>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { log } from "@/api/user";
export default {
  name: "LeftRig",
  data() {
    return {
      leftRig: [],// 存储轮播图和二级菜单数据
    };
  },
  mounted() {
    // 获取首页广告区数据，包括轮播图和右侧二级菜单
    log().then((res) => {
      this.leftRig = res.data.result;
    });
  },
  methods:{
    // 跳往二级路由
    Name(id){

      this.$router.push({path:"/NaviGation/CateGory",query:{id:id}})
    },
    // 跳往三级路由
    Desc(id){
      this.$router.push({path:"/NaviGation/CateGory/CateSub",query:{id:id}})
    },
    // 跳往详情页
    rights(id){
      this.$router.push({path: "/NaviGation/PartiCulars",query: {id:id},});
    }
  }
};
</script>

<style scoped>
#LeftRig {
  width: 250px;
  height: 500px;
  background: rgba(0, 0, 0, 0.8);
  z-index: 99;
  position: absolute;
  left:0;
  top:0;
}

#LeftRig > ul{
  display: flex;
  height:100%;
  flex-direction:column;
  justify-content: space-between;
}

#LeftRig > ul > li {
  padding-left: 40px;
  height: 50px;
  line-height: 50px;
}

#LeftRig > ul > li:hover{
  background: #27ba9b;
}

#LeftRig > ul > li > span {
  margin-right: 4px;
  color: #fff;
}

span{
  cursor: pointer;
}


.da {
  font-size: 16px;
}

.da2{
  font-size:12px;
}

.right{
 width: 1005px;
  height: 500px;
  background: hsla(0,0%,100%,.8);
  position: absolute;
  left: 250px;
  top: 0;
  display: none;
  padding: 0 15px;
}


.right h4{
  font-size: 20px;
  font-weight: 400;
  line-height: 80px;
}

.right h4 small{
    font-size: 16px;
    color: #666;
}

.right > ul {
  display: flex;
  flex-wrap: wrap;
}

.right > ul > li{
    width: 310px;
    height: 120px;
    margin-right: 15px;
    margin-bottom: 15px;
    border: 1px solid #eee;
    border-radius: 4px;
    background: #fff;
}

#LeftRig ul li:hover .right{
  display: block;
}

.right > ul > li > .lazy{
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    padding-left:10px;
}

.right > ul > li > .lazy > img{
    width: 95px;
    height: 95px;
}

img {
    vertical-align: middle;
}


.right > ul > li > .lazy > div{
  padding-left: 10px;
  line-height: 24px;
  width: 190px;
}

.right > ul > li > .lazy > div > p:nth-child(1){
  word-break: break-all;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  text-overflow: ellipsis;
  overflow: hidden;
  font-size: 16px;
  color: #666;
}

.right > ul > li > .lazy > div > p:nth-child(2){
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.right > ul > li > .lazy > div > p:nth-child(3){
  font-size: 22px;
  color: #cf4444;
}


.right > ul > li > .lazy:hover {
    background: #e3f9f4;
}


</style>

